import Notify from '@vant/weapp/notify/notify';
import Toast from '@vant/weapp/toast/toast';
import Dialog from '@vant/weapp/dialog/dialog';
import { request } from '../../assets/js/request.js';
Page({
  getClassDetail:function(){
    wx.showLoading({
      title: '加载数据',
      mask: true,
    })
    let reqData = {
      uid: this.data.uid,
      classId:this.data.classId,
      status:this.data.status
    }
    request('/getClassDetail.php',reqData)
      .then((res)=>{
        this.setData({
          signInfo:res.data.signInfo,
          classInfo:res.data.classInfo,
          stuList:res.data.stuList,
        })
        if (res.data.classInfo.isSign == 1) {
          this.setData({
            isSign: true,
          })
        } else {
          this.setData({
            isSign: false,
          })
        }
      })
      .catch((err)=>{
        Notify({ type: 'danger', message: '服务器繁忙，请稍后再试' });
      })
  },

  getStuId:function(e){
    wx.setStorageSync('stuId-sign', e.currentTarget.id)
  },

  handlerSign:function(e){
    if(!this.data.isSign){
      Toast({
        type: 'fail',
        message: '不是签到时间',
        mask: true,
        duration: 1000
      })
    }else{
      wx.navigateTo({
        url: '/pages/signNow/signNow',
      })
    }
  },

  handlerCopy:function(e){
    wx.setClipboardData({
      data: e.currentTarget.id,
      success:(res) => {
        wx.getClipboardData({
          success(res) {
            // console.log(res.data)
          }
        })
      }
    })
  },

  delClsStu:function(e){
    Dialog.confirm({
      title: '注意',
      message: '删除后数据无法恢复，您确定要删除该学生吗？'
    }).then(()=>{
      let delStuData = {
        stuId: e.currentTarget.id,
        classId: this.data.classId
      }
      wx.showLoading({
        title: '正在删除',
        mask: true,
      })
      request('/delClsStu.php', delStuData)
        .then((res) => {
          if (res.data == 'ok') {
            Notify({ type: 'success', message: '删除成功' });
            this.getClassDetail();
          } else {
            Notify({ type: 'danger', message: '服务器繁忙，请稍后再试' });
          }
        })
        .catch((err) => {
          Notify({ type: 'danger', message: '服务器异常' });
        })
    }).catch(()=>{})
  },

  data: {
    uid:'',
    status:'',
    classId:'',
    classInfo:[],
    signInfo:[],
    stuList:[],
    isSign: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      uid: wx.getStorageSync('uid'),
      status: wx.getStorageSync('status'),
      classId: wx.getStorageSync('classId')
    })
    this.getClassDetail();
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  onPullDownRefresh: function () {
    this.getClassDetail();
    wx.stopPullDownRefresh();
  },

})